<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class StuController extends Controller
{
    //
    
    public function index()
    {
       $list = \DB::table("stu")->get();
       return view("stu.index",["list"=>$list]);
    }

     public function index2()
    {
       $list = \DB::table("stu")->paginate(3);
       return view("stu.index2",["list"=>$list]);
    }

    public function create()
    {
    	//echo"加载add";
    	return view("stu.add");
    }

    public function store(Request $Request)
    {
    	//获取要添加的信息
    	//$name = $Request->input("name");
    	  //$data = $Request->all();
    	  //unset($data['_token']);
    	//dd($data);

    	//获取部分指定的部分数据
    	$data = $Request->only("name","sex","age","classid");
    	//dd($data);
    	$id = \DB::table("stu")->insertGetId($data);
    	if($id>0){
    		echo"插入成功";
    	}else{
    		echo"插入失败";
    	}
    }

    //执行删除
    public function destroy($id)
    {
    	\DB::table("stu")->where("id",$id)->delete();
    	return $this->index();
    }

    //执行修改
   public function edit($id)
   {
   	$stu = \DB::table("stu")->where("id",$id)->first();
    return view("stu.edit",["vo"=>$stu]);
   }

   //执行修改
   public function update($id,Request $Request)
   {
   		$data = $Request->only("name","sex","age","classid");
   		//dd($data);
   		$id = \DB::table("stu")->where("id",$id)->update($id);
   		if($id){
   			return "修改成功";
   		}else{
   			return "修改失败";
   		}
   }
}
